clc
close all
clear all

N = 5
D = 3
X = rand(N, D);
C = rand(N, N);

S = linearObjective(C, X);
gS = linearGradient(C, X);

for i = 1:N
    for j = 1:D
        X2 = X;
        X2(i, j) = X2(i, j) - 1e-6;
        X3 = X;
        X3(i, j) = X3(i, j) + 1e-6;
        gg(:, :, i, j) = 0.5*(linearObjective(C, X3)-linearObjective(C, X2))/1e-6;
    end
end

sum((gg(:)-gS(:)).^2)